home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVIPS_55 / dvips / src / c / afm2tfm next >
Text File  |  1994-05-06  |  53KB  |  1,890 lines

  1. /*
  2.  *   This program converts AFM files to TeX TFM files, and optionally
  3.  *   to TeX VPL files that retain all kerning and ligature information.
  4.  *   Both files make the characters not normally encoded by TeX available
  5.  *   by character codes greater than 127.
  6.  */
  7.  
  8. /*   (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) */
  9. /*   VM/CMS port by J. Hafner (hafner@almaden.ibm.com), based on
  10.  *   the port by Alessio Guglielmi (guglielmi@ipisnsib.bitnet)
  11.  *   and Marco Prevedelli (prevedelli@ipisnsva.bitnet).
  12.  *   This port is still in test state.  No guarantees.
  13.  *   11/3/92: more corrections to VM/CMS port. Now it looks correct
  14.  *   and will be supported by J. Hafner.
  15.  *
  16. */
  17.  
  18. #include <stdio.h>
  19. #if defined(OS2)
  20. #include <stdlib.h>
  21. #endif
  22. #if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS) || defined(OS2)
  23. #include <string.h>
  24. #else
  25. #include <strings.h>
  26. #endif
  27. #include <math.h>
  28.  
  29. /* JLH: added these to make the code easier to read and remove some
  30.    ascii<->ebcdic dependencies */
  31. #define ASCII_A 65
  32. #define ASCII_Z 90
  33. #define ASCII_a 97
  34. #define ASCII_z 122
  35. #define ASCII_0 48
  36. #define ASCII_9 57
  37.  
  38. #ifdef VMCMS
  39. #define interesting lookstr  /* for 8 character truncation conflicts */
  40. #include "dvipscms.h"
  41. extern FILE *cmsfopen() ;
  42. extern char ebcdic2ascii[] ;
  43. extern char ascii2ebcdic[] ;
  44. #ifdef fopen
  45. #undef fopen
  46. #endif
  47. #define fopen cmsfopen
  48. #endif
  49.  
  50. #if defined MSDOS || defined OS2
  51. #define WRITEBIN "wb"
  52. #else
  53. #ifdef VMCMS
  54. #define WRITEBIN "wb, lrecl=1024, recfm=f"
  55. #else
  56. #define WRITEBIN "w"
  57. #endif
  58. #endif
  59.  
  60. #if (defined(MSDOS) && defined(__TURBOC__)) || (defined(OS2) && defined(_MSC_VER))
  61. #define SMALLMALLOC
  62. #endif
  63.  
  64. struct encoding {
  65.    char *name ;
  66.    char *vec[256] ;
  67. } ;
  68. struct encoding staticencoding = {
  69.   "TeX text",
  70.   {"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma",
  71.    "Upsilon", "Phi", "Psi", "Omega", "arrowup", "arrowdown", "quotesingle",
  72.    "exclamdown", "questiondown", "dotlessi", "dotlessj", "grave", "acute",
  73.    "caron", "breve", "macron", "ring", "cedilla", "germandbls", "ae", "oe",
  74.    "oslash", "AE", "OE", "Oslash", "space", "exclam", "quotedbl", "numbersign",
  75.    "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
  76.    "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
  77.    "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
  78.    "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
  79.    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  80.    "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
  81.    "bracketright", "circumflex", "underscore", "quoteleft", "a", "b", "c", "d",
  82.    "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  83.    "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
  84.    "tilde", "dieresis", "", "", "", "", "", "", "", "", "", "", "", "", "",
  85.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  86.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  87.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  88.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  89.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  90.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  91.     "", "", "", "", "", "", "" } } ;
  92. /*
  93.  *   It's easier to put this in static storage and parse it as we go
  94.  *   than to build the structures ourselves.
  95.  */
  96. char *staticligkern[] = {
  97.    "% LIGKERN space l =: lslash ; space L =: Lslash ;",
  98.    "% LIGKERN question quoteleft =: questiondown ;",
  99.    "% LIGKERN exclam quoteleft =: exclamdown ;",
  100.    "% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;",
  101.    "% LIGKERN quoteleft quoteleft =: quotedblleft ;",
  102.    "% LIGKERN quoteright quoteright =: quotedblright ;",
  103.    "% LIGKERN space {} * ; * {} space ; zero {} * ; * {} zero ;",
  104.    "% LIGKERN one {} * ; * {} one ; two {} * ; * {} two ;",
  105.    "% LIGKERN three {} * ; * {} three ; four {} * ; * {} four ;",
  106.    "% LIGKERN five {} * ; * {} five ; six {} * ; * {} six ;",
  107.    "% LIGKERN seven {} * ; * {} seven ; eight {} * ; * {} eight ;",
  108.    "% LIGKERN nine {} * ; * {} nine ;",
  109. /*
  110.  *   These next are only included for deficient afm files that
  111.  *   have the lig characters but not the lig commands.
  112.  */
  113.    "% LIGKERN f i =: fi ; f l =: fl ; f f =: ff ; ff i =: ffi ;",
  114.    "% LIGKERN ff l =: ffl ;",
  115.    0 } ;
  116. /*
  117.  *   The above layout corresponds to TeX Typewriter Type and is compatible
  118.  *   with TeX Text because the position of ligatures is immaterial.
  119.  */
  120. struct encoding *outencoding = 0 ;
  121. struct encoding *inencoding = 0 ;
  122. char *outenname, *inenname ;/* the file names for input and output encodings */
  123. int boundarychar = -1 ;     /* the boundary character */
  124. int ignoreligkern ;         /* do we look at ligkern info in the encoding? */
  125. /*
  126.  *   This is what we store Adobe data in.
  127.  */
  128. struct adobeinfo {
  129.    struct adobeinfo *next ;
  130.    int adobenum, texnum, width ;
  131.    char *adobename ;
  132.    int llx, lly, urx, ury ;
  133.    struct lig *ligs ;
  134.    struct kern *kerns ;
  135.    struct pcc *pccs ;
  136.    int wptr, hptr, dptr, iptr ;
  137. } *adobechars, *adobeptrs[256], *texptrs[256],
  138.   *uppercase[256], *lowercase[256] ;
  139. int nexttex[256] ; /* for characters encoded multiple times in output */
  140. /*
  141.  *   These are the eight ligature ops, in VPL terms and in METAFONT terms.
  142.  */
  143. char *vplligops[] = {
  144.    "LIG", "/LIG", "/LIG>", "LIG/", "LIG/>", "/LIG/", "/LIG/>", "/LIG/>>", 0
  145. } ;
  146. char *encligops[] = {
  147.    "=:", "|=:", "|=:>", "=:|", "=:|>", "|=:|", "|=:|>", "|=:|>>", 0
  148. } ;
  149. struct lig {
  150.    struct lig *next ;
  151.    char *succ, *sub ;
  152.    short op, boundleft ;
  153. } ;
  154. struct kern {
  155.    struct kern *next ;
  156.    char *succ ;
  157.    int delta ;
  158. } ;
  159. struct pcc {
  160.    struct pcc *next ;
  161.    char * partname ;
  162.    int xoffset, yoffset ;
  163. } ;
  164.  
  165. FILE *afmin, *vplout, *tfmout ;
  166. char inname[200], outname[200] ; /* names of input and output files */
  167. char buffer[255]; /* input buffer (modified while parsing) */
  168. char obuffer[255] ; /* unmodified copy of input buffer */
  169. char *param ; /* current position in input buffer */
  170. char *fontname = "Unknown" ;
  171. char *codingscheme = "Unspecified" ;
  172. #ifdef VMCMS
  173. char *ebfontname ;
  174. char *ebcodingscheme ;
  175. #endif
  176. float italicangle = 0.0 ;
  177. char fixedpitch ;
  178. char makevpl ;
  179. char pedantic ;
  180. int xheight = 400 ;
  181. int fontspace ;
  182. int bc, ec ;
  183. long cksum ;
  184. float efactor = 1.0, slant = 0.0 ;
  185. float capheight = 0.8 ;
  186. char *efactorparam, *slantparam ;
  187. double newslant ;
  188. char titlebuf[500] ;
  189.  
  190. void
  191. error(s)
  192. register char *s ;
  193. {
  194.    extern void exit() ;
  195.  
  196.    (void)fprintf(stderr, "%s\n", s) ;
  197.    if (obuffer[0]) {
  198.       (void)fprintf(stderr, "%s\n", obuffer) ;
  199.       while (param > buffer) {
  200.          (void)fprintf(stderr, " ") ;
  201.          param-- ;
  202.       }
  203.       (void)fprintf(stderr, "^\n") ;
  204.    }
  205.    if (*s == '!')
  206.       exit(1) ;
  207. }
  208.  
  209. int
  210. transform(x,y)
  211.    register int x,y ;
  212. {
  213.    register double acc ;
  214.    acc = efactor * x + slant *y ;
  215.    return (int)(acc>=0? floor(acc+0.5) : ceil(acc-0.5) ) ;
  216. }
  217.  
  218. int
  219. getline() {
  220.    register char *p ;
  221.    register int c ;
  222.  
  223.    param = buffer ;
  224.    for (p=buffer; (c=getc(afmin)) != EOF && c != '\n';)/* changed 10 to '\n' */
  225.       *p++ = c ;
  226.    *p = 0 ;
  227.    (void)strcpy(obuffer, buffer) ;
  228.    if (p == buffer && c == EOF)
  229.       return(0) ;
  230.    else
  231.       return(1) ;
  232. }
  233.  
  234. char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
  235.    "XHeight", "C", "KPX", "CC", "EncodingScheme", NULL} ;
  236. #define FontName (0)
  237. #define ItalicAngle (1)
  238. #define IsFixedPitch (2)
  239. #define XHeight (3)
  240. #define C (4)
  241. #define KPX (5)
  242. #define CC (6)
  243. #define EncodingScheme (7)
  244. #define NONE (-1)
  245. int
  246. interest(s)
  247. char *s ;
  248. {
  249.    register char **p ;
  250.    register int n ;
  251.  
  252.    for (p=interesting, n=0; *p; p++, n++)
  253.       if (strcmp(s, *p)==0)
  254.          return(n) ;
  255.    return(NONE) ;
  256. }
  257.  
  258. char *
  259. mymalloc(len)
  260. unsigned long len ;
  261. {
  262.    register char *p ;
  263.    int i ;
  264. #ifndef IBM6000
  265. #if defined MSDOS || defined OS2
  266.    extern void *malloc() ;
  267. #else
  268.    extern char *malloc() ;
  269. #endif
  270. #endif
  271.  
  272. #ifdef SMALLMALLOC
  273.    if (len > 65500L)
  274.       error("! can't allocate more than 64K!") ;
  275. #endif
  276.    p = malloc((unsigned)len) ;
  277.    if (p==NULL)
  278.       error("! out of memory") ;
  279.    for (i=0; i<len; i++)
  280.       p[i] = 0 ;
  281.    return(p) ;
  282. }
  283.  
  284. char *
  285. newstring(s)
  286. char *s ;
  287. {
  288.    char *q = mymalloc((unsigned long)(strlen(s) + 1)) ;
  289.    (void)strcpy(q, s) ;
  290.    return q ;
  291. }
  292.  
  293. char *
  294. paramnewstring() {
  295.    register char *p, *q ;
  296.  
  297.    p = param ;
  298.    while (*p > ' ')
  299.       p++ ;
  300.    if (*p != 0)
  301.       *p++ = 0 ;
  302.    q = newstring(param) ;
  303.    while (*p && *p <= ' ')
  304.       p++ ;
  305.    param = p ;
  306.    return(q) ;
  307. }
  308.  
  309. char *
  310. paramstring() {
  311.    register char *p, *q ;
  312.  
  313.    p = param ;
  314.    while (*p > ' ')
  315.       p++ ;
  316.    q = param ;
  317.    if (*p != 0)
  318.       *p++ = 0 ;
  319.    while (*p && *p <= ' ')
  320.       p++ ;
  321.    param = p ;
  322.    return(q) ;
  323. }
  324.  
  325. int
  326. paramnum() {
  327.    register char *p ;
  328.    int i ;
  329.  
  330.    p = paramstring() ;
  331.    if (sscanf(p, "%d", &i) != 1)
  332.       error("! integer expected") ;
  333.    return(i) ;
  334. }
  335.  
  336. float
  337. paramfloat() {
  338.    register char *p ;
  339.    float i ;
  340.  
  341.    p = paramstring() ;
  342.    if (sscanf(p, "%f", &i) != 1)
  343.       error("! number expected") ;
  344.    return(i) ;
  345. }
  346.  
  347. struct adobeinfo *
  348. newchar() {
  349.    register struct adobeinfo *ai ;
  350.  
  351.    ai = (struct adobeinfo *)mymalloc((unsigned long)sizeof(struct adobeinfo)) ;
  352.    ai->adobenum = -1 ;
  353.    ai->texnum = -1 ;
  354.    ai->width = -1 ;
  355.    ai->adobename = NULL ;
  356.    ai->llx = -1 ;
  357.    ai->lly = -1 ;
  358.    ai->urx = -1 ;
  359.    ai->ury = -1 ;
  360.    ai->ligs = NULL ;
  361.    ai->kerns = NULL ;
  362.    ai->pccs = NULL ;
  363.    ai->next = adobechars ;
  364.    adobechars = ai ;
  365.    return(ai) ;
  366. }
  367.  
  368. struct kern *
  369. newkern() {
  370.    register struct kern *nk ;
  371.  
  372.    nk = (struct kern *)mymalloc((unsigned long)sizeof(struct kern)) ;
  373.    nk->next = NULL ;
  374.    nk->succ = NULL ;
  375.    nk->delta = 0 ;
  376.    return(nk) ;
  377. }
  378.  
  379. struct pcc *
  380. newpcc() {
  381.    register struct pcc *np ;
  382.  
  383.    np = (struct pcc *)mymalloc((unsigned long)sizeof(struct pcc)) ;
  384.    np->next = NULL ;
  385.    np->partname = NULL ;
  386.    np->xoffset = 0 ;
  387.    np->yoffset = 0 ;
  388.    return(np) ;
  389. }
  390.  
  391. struct lig *
  392. newlig() {
  393.    register struct lig *nl ;
  394.  
  395.    nl = (struct lig *)mymalloc((unsigned long)sizeof(struct lig)) ;
  396.    nl->next = NULL ;
  397.    nl->succ = NULL ;
  398.    nl->sub = NULL ;
  399.    nl->op = 0 ; /* the default =: op */
  400.    nl->boundleft = 0 ;
  401.    return(nl) ;
  402. }
  403.  
  404. void
  405. expect(s)
  406. char *s ;
  407. {
  408.    if (strcmp(paramstring(), s) != 0) {
  409.       (void)fprintf(stderr, "%s expected: ", s) ;
  410.       error("! syntax error") ;
  411.    }
  412. }
  413.  
  414. void
  415. handlechar() { /* an input line beginning with C */
  416.    register struct adobeinfo *ai ;
  417.    register struct lig *nl ;
  418.  
  419.    ai = newchar() ;
  420.    ai->adobenum = paramnum() ;
  421.    expect(";") ;
  422.    expect("WX") ;
  423.    ai->width = transform(paramnum(),0) ;
  424.    if (ai->adobenum >= 0 && ai->adobenum < 256) {
  425.       adobeptrs[ai->adobenum] = ai ;
  426.    }
  427.    expect(";") ;
  428.    expect("N") ;
  429.    ai->adobename = paramnewstring() ;
  430.    expect(";") ;
  431.    expect("B") ;
  432.    ai->llx = paramnum() ;
  433.    ai->lly = paramnum() ;
  434.    ai->llx = transform(ai->llx, ai->lly) ;
  435.    ai->urx = paramnum() ;
  436.    ai->ury = paramnum() ;
  437.    ai->urx = transform(ai->urx, ai->ury) ;
  438. /* We need to avoid negative heights or depths. They break accents in
  439.    math mode, among other things.  */
  440.    if (ai->lly > 0)
  441.       ai->lly = 0 ;
  442.    if (ai->ury < 0)
  443.       ai->ury = 0 ;
  444.    expect(";") ;
  445. /* Now look for ligatures (which aren't present in fixedpitch fonts) */
  446.    while (*param == 'L' && !fixedpitch) {
  447.       expect("L") ;
  448.       nl = newlig() ;
  449.       nl->succ = paramnewstring() ;
  450.       nl->sub = paramnewstring() ;
  451.       nl->next = ai->ligs ;
  452.       ai->ligs = nl ;
  453.       expect(";") ;
  454.    }
  455. }
  456.  
  457. struct adobeinfo *
  458. findadobe(p)
  459. char *p ;
  460. {
  461.    register struct adobeinfo *ai ;
  462.  
  463.    for (ai=adobechars; ai; ai = ai->next)
  464.       if (strcmp(p, ai->adobename)==0)
  465.          return(ai) ;
  466.    return(NULL) ;
  467. }
  468.  
  469.  
  470. /*
  471.  *   The following comment no longer applies; we rely on the LIGKERN
  472.  *   entries to kill space kerns.  Also, the same applies to numbers.
  473.  *
  474.  * We ignore kerns before and after space characters, because (1) TeX
  475.  * is using the space only for Polish ligatures, and (2) TeX's
  476.  * boundarychar mechanisms are not oriented to kerns (they apply
  477.  * to both spaces and punctuation) so we don't want to use them.
  478.  */
  479. void
  480. handlekern() { /* an input line beginning with KPX */
  481.    register struct adobeinfo *ai ;
  482.    register char *p ;
  483.    register struct kern *nk ;
  484.  
  485.    p = paramstring() ;
  486.    ai = findadobe(p) ;
  487.    if (ai == NULL)
  488.       error("kern char not found") ;
  489.    else {
  490.       nk = newkern() ;
  491.       nk->succ = paramnewstring() ;
  492.       nk->delta = transform(paramnum(),0) ;
  493.       nk->next = ai->kerns ;
  494.       ai->kerns = nk ;
  495.     }
  496. }
  497.  
  498. void
  499. handleconstruct() { /* an input line beginning with CC */
  500.    register struct adobeinfo *ai ;
  501.    register char *p ;
  502.    register struct pcc *np ;
  503.    register int n ;
  504.    struct pcc *npp = NULL;
  505.  
  506.    p = paramstring() ;
  507.    ai = findadobe(p) ;
  508.    if (ai == NULL)
  509.       error("! composite character name not found") ;
  510.    n = paramnum() ;
  511.    expect(";") ;
  512.    while (n--) {
  513.       if (strcmp(paramstring(),"PCC") != 0) return ;
  514.         /* maybe I should expect("PCC") instead, but I'm playing it safe */
  515.       np = newpcc() ;
  516.       np->partname = paramnewstring() ;
  517.       if (findadobe(np->partname)==NULL) return ;
  518.       np->xoffset = paramnum() ;
  519.       np->yoffset = paramnum() ;
  520.       np->xoffset = transform(np->xoffset, np->yoffset) ;
  521.       if (npp) npp->next = np ;
  522.       else ai->pccs = np ;
  523.       npp = np ;
  524.       expect(";") ;
  525.    }
  526. }
  527.  
  528. struct encoding *readencoding() ;
  529.  
  530. void
  531. makeaccentligs() {
  532.    register struct adobeinfo *ai, *aci ;
  533.    register char *p ;
  534.    register struct lig *nl ;
  535.    for (ai=adobechars; ai; ai=ai->next) {
  536.       p = ai->adobename ;
  537.       if (strlen(p)>2)
  538.          if ((aci=findadobe(p+1)) && (aci->adobenum > 127)) {
  539.             nl = newlig() ;
  540.             nl->succ = mymalloc((unsigned long)2) ;
  541.             *(nl->succ + 1) = 0 ;
  542.             *(nl->succ) = *p ;
  543.             nl->sub = ai->adobename ;
  544.             nl->next = aci->ligs ;
  545.             aci->ligs = nl ;
  546.          }
  547.    }
  548. }
  549.  
  550. void
  551. readadobe() {
  552.    struct adobeinfo *ai ;
  553. #ifdef VMCMS
  554.     int i;
  555. #endif
  556.  
  557. /*
  558.  *   We allocate a placeholder boundary char.
  559.  */
  560.    ai = newchar() ;
  561.    ai->adobenum = -1 ;
  562.    ai->adobename = "||" ; /* boundary character name */
  563.    while (getline()) {
  564.       switch(interest(paramstring())) {
  565. case FontName:
  566.          fontname = paramnewstring() ;
  567. #ifdef VMCMS
  568. /* fontname comes in as ebcdic but we need it asciified for tfm file
  569.    so we save it in ebfontname and change it in fontname */
  570.    ebfontname = newstring(fontname) ;
  571.    i=0;
  572.    while(fontname[i] != '\0') {
  573.       fontname[i]=ebcdic2ascii[fontname[i]];
  574.       i++;
  575.    };
  576. #endif
  577.          break ;
  578. case EncodingScheme:
  579.          codingscheme = paramnewstring() ;
  580. #ifdef VMCMS
  581. /* for codingscheme, we do the same as we did for fontname */
  582.    ebcodingscheme = newstring(codingscheme) ;
  583.    i=0;
  584.    while(codingscheme[i] != '\0') {
  585.       codingscheme[i]=ebcdic2ascii[codingscheme[i]];
  586.       i++;
  587.    }
  588. #endif
  589.          break ;
  590. case ItalicAngle:
  591.          italicangle = paramfloat() ;
  592.          break ;
  593. case IsFixedPitch:
  594.          if (*param == 't' || *param == 'T')
  595.             fixedpitch = 1 ;
  596.          else
  597.             fixedpitch = 0 ;
  598.          break ;
  599. case XHeight:
  600.          xheight = paramnum() ;
  601.          break ;
  602. case C:
  603.          handlechar() ;
  604.          break ;
  605. case KPX:
  606.          handlekern() ;
  607.          break ;
  608. case CC:
  609.          handleconstruct() ;
  610.          break ;
  611. default:
  612.          break ;
  613.       }
  614.    }
  615.    fclose(afmin) ;
  616.    afmin = 0 ;
  617. }
  618. /*
  619.  *   Re-encode the adobe font.  Assumes that the header file will
  620.  *   also contain the appropriate instructions!
  621.  */
  622. void
  623. handlereencoding() {
  624.    if (inenname) {
  625.       int i ;
  626.       struct adobeinfo *ai ;
  627.       char *p ;
  628.  
  629.       ignoreligkern = 1 ;
  630.       inencoding = readencoding(inenname) ;
  631.       for (i=0; i<256; i++)
  632.          if (0 != (ai=adobeptrs[i])) {
  633.             ai->adobenum = -1 ;
  634.             adobeptrs[i] = NULL ;
  635.          }
  636.       for (i=0; i<256; i++) {
  637.          p = inencoding->vec[i] ;
  638.          if (p && *p && 0 != (ai = findadobe(p))) {
  639.             ai->adobenum = i ;
  640.             adobeptrs[i] = ai ;
  641.          }
  642.       }
  643.       codingscheme = inencoding->name ;
  644.    }
  645.    ignoreligkern = 0 ;
  646.    if (outenname) {
  647.       outencoding = readencoding(outenname) ;
  648.    } else {
  649.       outencoding = readencoding((char *)0) ;
  650.    }
  651. }
  652.  
  653. /*
  654.  *   This routine reverses a list.  We use it because we accumulate the
  655.  *   adobeinfo list in reverse order, but when we go to map the
  656.  *   characters, we would prefer to use the original ordering.  It just
  657.  *   makes more sense.
  658.  */
  659. struct adobeinfo *revlist(p)
  660. struct adobeinfo *p ;
  661. {
  662.    struct adobeinfo *q = 0, *t ;
  663.  
  664.    while (p) {
  665.       t = p->next ;
  666.       p->next = q ;
  667.       q = p ;
  668.       p = t ;
  669.    }
  670.    return (void *)q ;
  671. }
  672.  
  673. void
  674. assignchars() {
  675.    register char **p ;
  676.    register int i, j ;
  677.    register struct adobeinfo *ai, *pai ;
  678.    int nextfree = 128 ;
  679.    struct pcc *pcp ;
  680.  
  681. /*
  682.  *   First, we assign all those that match perfectly.
  683.  */
  684.    for (i=0, p=outencoding->vec; i<256; i++, p++)
  685.       if ((ai=findadobe(*p)) && (ai->adobenum >= 0 || ai->pccs != NULL)) {
  686.          if (ai->texnum >= 0)
  687.             nexttex[i] = ai->texnum ; /* linked list */
  688.          ai->texnum = i ;
  689.          texptrs[i] = ai ;
  690.       }
  691.    if (pedantic)
  692.       return ;
  693. /*
  694.  *   Next, we assign all the others, retaining the adobe positions, possibly
  695.  *   multiply assigning characters.
  696.  */
  697.    for (ai=adobechars; ai; ai=ai->next)
  698.       if (ai->adobenum >= 0 && ai->texnum < 0 && texptrs[ai->adobenum]==0) {
  699.          ai->texnum = ai->adobenum ;
  700.          texptrs[ai->adobenum] = ai ;
  701.       }
  702. /*
  703.  *   Finally, we map all remaining characters into free locations beginning
  704.  *   with 128, if we know how to construct those characters.  We need to
  705.  *   make sure the component pieces are mapped.
  706.  */
  707.    adobechars = revlist(adobechars) ;
  708.    for (ai=adobechars; ai; ai=ai->next)
  709.       if (ai->texnum<0 && (ai->adobenum>=0 || ai->pccs != NULL)) {
  710.          while (texptrs[nextfree]) {
  711.             nextfree=(nextfree+1)&255 ;
  712.             if (nextfree==128) goto finishup ; /* all slots full */
  713.          }
  714.          ai->texnum = nextfree ;
  715.          texptrs[nextfree] = ai ;
  716.       }
  717. finishup:
  718. /*
  719.  *   We now check all of the composite characters.  If any of the
  720.  *   components are not mapped, we unmap the composite character.
  721.  */
  722.    for (i=0; i<256; i++) {
  723.       ai = texptrs[i] ;
  724.       if (ai && ai->pccs != NULL && ai->texnum >= 0) {
  725.          for (pcp = ai->pccs; pcp; pcp = pcp->next) {
  726.             pai = findadobe(pcp->partname) ;
  727.             if (pai == NULL || pai->texnum < 0) {
  728.                texptrs[ai->texnum] = 0 ;
  729.                ai->texnum = -1 ;
  730.                break ;
  731.             }
  732.          }
  733.       }
  734.    }
  735. /*
  736.  *   Now, if any of the characters are encoded multiple times, we want
  737.  *   ai->texnum to be the first one assigned, since that is most likely
  738.  *   to be the most important one.  So we reverse the above lists.
  739.  */
  740.    for (ai=adobechars; ai; ai=ai->next)
  741.       if (ai->texnum >= 0) {
  742.          j = -1 ;
  743.          while (nexttex[ai->texnum] >= 0) {
  744.             i = nexttex[ai->texnum] ;
  745.             nexttex[ai->texnum] = j ;
  746.             j = ai->texnum ;
  747.             ai->texnum = i ;
  748.          }
  749.          nexttex[ai->texnum] = j ;
  750.       }
  751. }
  752.  
  753. void
  754. upmap() { /* Compute uppercase mapping, when making a small caps font */
  755.    register struct adobeinfo *ai, *Ai ;
  756.    register char *p, *q ;
  757.    register struct pcc *np, *nq ;
  758.    int i ;
  759.    char lwr[50] ;
  760.  
  761. /* JLH: changed some lines below to be ascii<->ebcdic independent */
  762. /* any reason we don't use 'isupper'? */
  763.    for (Ai=adobechars; Ai; Ai=Ai->next) {
  764.       p = Ai->adobename ;
  765. #ifndef VMCMS
  766.       if (*p>=ASCII_A && *p<=ASCII_Z) {
  767. #else
  768.       if (ebcdic2ascii[*p]>=ASCII_A && ebcdic2ascii[*p]<=ASCII_Z) {
  769. #endif
  770.          q = lwr ;
  771.          for (; *p; p++)
  772. #ifndef VMCMS
  773.             *q++ = ((*p>=ASCII_A && *p<=ASCII_Z) ? *p+32 : *p) ;
  774. #else
  775.             *q++ = ((ebcdic2ascii[*p]>=ASCII_A &&
  776.                         ebcdic2ascii[*p]<=ASCII_Z ) ?
  777.                             ascii2ebcdic[ebcdic2ascii[*p]+32] : *p) ;
  778. #endif
  779.          *q = '\0';   /* changed this too! */
  780.  
  781.          if (0 != (ai=findadobe(lwr))) {
  782.             for (i = ai->texnum; i >= 0; i = nexttex[i])
  783.                uppercase[i] = Ai ;
  784.             for (i = Ai->texnum; i >= 0; i = nexttex[i])
  785.                lowercase[i] = ai ;
  786.          }
  787.       }
  788.    }
  789. /* Note that, contrary to the normal true/false conventions,
  790.  * uppercase[i] is NULL and lowercase[i] is non-NULL when i is the
  791.  * ASCII code of an uppercase letter; and vice versa for lowercase letters */
  792.  
  793.    if (0 != (ai=findadobe("germandbls")))
  794.       if (0 != (Ai=findadobe("S"))) { /* we also construct SS */
  795.          for (i=ai->texnum; i >= 0; i = nexttex[i])
  796.             uppercase[i] = ai ;
  797.          ai->adobenum = -1 ;
  798.          ai->width = Ai->width << 1 ;
  799.          ai->llx = Ai->llx ;
  800.          ai->lly = Ai->lly ;
  801.          ai->urx = Ai->width + Ai->urx ;
  802.          ai->ury = Ai->ury ;
  803.          ai->kerns = Ai->kerns ;
  804.          np = newpcc() ;
  805.          np->partname = "S" ;
  806.          nq = newpcc() ;
  807.          nq->partname = "S" ;
  808.          nq->xoffset = Ai->width ;
  809.          np->next = nq ;
  810.          ai->pccs = np ;
  811.       }
  812.    if ((ai=findadobe("dotlessi")))
  813.       for (i=ai->texnum; i >= 0; i = nexttex[i])
  814.          uppercase[i] = findadobe("I") ;
  815.    if ((ai=findadobe("dotlessj")))
  816.       for (i=ai->texnum; i >= 0; i = nexttex[i])
  817.          uppercase[i] = findadobe("J") ;
  818. }
  819. /* The logic above seems to work well enough, but it leaves useless characters
  820.  * like `fi' and `fl' in the font if they were present initially,
  821.  * and it omits characters like `dotlessj' if they are absent initially */
  822.  
  823. /* Now we turn to computing the TFM file */
  824.  
  825. int lf, lh, nw, nh, nd, ni, nl, nk, ne, np ;
  826.  
  827. void
  828. write16(what)
  829. register short what ;
  830. {
  831.    (void)fputc(what >> 8, tfmout) ;
  832.    (void)fputc(what & 255, tfmout) ;
  833. }
  834.  
  835. void
  836. writearr(p, n)
  837. register long *p ;
  838. register int n ;
  839. {
  840.    while (n) {
  841.       write16((short)(*p >> 16)) ;
  842.       write16((short)(*p & 65535)) ;
  843.       p++ ;
  844.       n-- ;
  845.    }
  846. }
  847.  
  848. void
  849. makebcpl(p, s, n)
  850. register long *p ;
  851. register char *s ;
  852. register int n ;
  853. {
  854.    register long t ;
  855.    register long sc ;
  856.  
  857.    if (strlen(s) < n)
  858.       n = strlen(s) ;
  859.    t = ((long)n) << 24 ;
  860.    sc = 16 ;
  861.    while (n > 0) {
  862.       t |= ((long)(*(unsigned char *)s++)) << sc ;
  863.       sc -= 8 ;
  864.       if (sc < 0) {
  865.          *p++ = t ;
  866.          t = 0 ;
  867.          sc = 24 ;
  868.       }
  869.       n-- ;
  870.    }
  871.    *p++ = t ;
  872. }
  873.  
  874. int source[257] ;
  875. int unsort[257] ;
  876.  
  877. /*
  878.  *   Next we need a routine to reduce the number of distinct dimensions
  879.  *   in a TFM file. Given an array what[0]...what[oldn-1], we want to
  880.  *   group its elements into newn clusters, in such a way that the maximum
  881.  *   difference between elements of a cluster is as small as possible.
  882.  *   Furthermore, what[0]=0, and this value must remain in a cluster by
  883.  *   itself. Data such as `0 4 6 7 9' with newn=3 shows that an iterative
  884.  *   scheme in which 6 is first clustered with 7 will not work. So we
  885.  *   borrow a neat algorithm from METAFONT to find the true optimum.
  886.  *   Memory location what[oldn] is set to 0x7fffffffL for convenience.
  887.  */
  888. long nextd ; /* smallest value that will give a different mincover */
  889. int
  890. mincover(what,d) /* tells how many clusters result, given max difference d */
  891. register long d ;
  892. long *what ;
  893. {
  894.    register int m ;
  895.    register long l ;
  896.    register long *p ;
  897.  
  898.    nextd = 0x7fffffffL ;
  899.    p = what+1 ;
  900.    m = 1 ;
  901.    while (*p<0x7fffffffL) {
  902.       m++ ;
  903.       l = *p ;
  904.       while (*++p <= l+d) ;
  905.       if (*p-l < nextd) nextd = *p-l ;
  906.    }
  907.    return (m) ;
  908. }
  909.  
  910. void
  911. remap(what, oldn, newn)
  912. long *what ;
  913. int oldn, newn ;
  914. {
  915.    register int i, j ;
  916.    register long d, l ;
  917.  
  918.    what[oldn] = 0x7fffffffL ;
  919.    for (i=oldn-1; i>0; i--) {
  920.       d = what[i] ;
  921.       for (j=i; what[j+1]<d; j++) {
  922.          what[j] = what[j+1] ;
  923.          source[j] = source[j+1] ;
  924.       }
  925.       what[j] = d ;
  926.       source[j] = i ;
  927.    } /* Tom, don't let me ever catch you using bubblesort again! -- Don */
  928.  
  929.    i = mincover(what, 0L) ;
  930.    d = nextd ;
  931.    while (mincover(what,d+d)>newn) d += d ;
  932.    while (mincover(what,d)>newn) d = nextd ;
  933.  
  934.    i = 1 ;
  935.    j = 0 ;
  936.    while (i<oldn) {
  937.       j++ ;
  938.       l = what[i] ;
  939.       unsort[source[i]] = j ;
  940.       while (what[++i] <= l+d) {
  941.          unsort[source[i]] = j ;
  942.          if (i-j == oldn-newn) d = 0 ;
  943.       }
  944.       what[j] = (l+what[i-1])/2 ;
  945.    }
  946. }
  947.  
  948. long checksum() {
  949.    int i ;
  950.    long s1 = 0, s2 = 0 ;
  951.    char *p ;
  952.    struct adobeinfo *ai ;
  953.  
  954.    for (i=0; i<256; i++)
  955.       if (0 != (ai=adobeptrs[i])) {
  956.          s1 = (s1 << 1) ^ ai->width ;
  957.          for (p=ai->adobename; *p; p++)
  958. #ifndef VMCMS
  959.             s2 = (s2 * 3) + *p ;
  960. #else
  961.             s2 = (s2 * 3) + ebcdic2ascii[*p] ;
  962. #endif
  963.       }
  964.    s1 = (s1 << 1) ^ s2 ;
  965.    return s1 ;
  966. }
  967.  
  968. /*
  969.  *   The next routine simply scales something.
  970.  *   Input is in 1000ths of an em.  Output is in FIXFACTORths of 1000.
  971.  */
  972. #define FIXFACTOR (0x100000L) /* 2^{20}, the unit fixnum */
  973. long
  974. scale(what)
  975. long what ;
  976. {
  977.    return(((what / 1000) << 20) +
  978.           (((what % 1000) << 20) + 500) / 1000) ;
  979. }
  980.  
  981. long *header, *charinfo, *width, *height, *depth, *ligkern, *kern, *tparam,
  982.      *italic ;
  983. long *tfmdata ;
  984.  
  985. void
  986. buildtfm() {
  987.    register int i, j ;
  988.    register struct adobeinfo *ai ;
  989.  
  990.    header = tfmdata ;
  991.    cksum = checksum() ;
  992.    header[0] = cksum ;
  993.    header[1] = 0xa00000 ; /* 10pt design size */
  994.    makebcpl(header+2, codingscheme, 39) ;
  995.    makebcpl(header+12, fontname, 19) ;
  996.    lh = 17 ;
  997.    charinfo = header + lh ;
  998.  
  999.    for (i=0; i<256 && adobeptrs[i]==NULL; i++) ;
  1000.    bc = i ;
  1001.    for (i=255; i>=0 && adobeptrs[i]==NULL; i--) ;
  1002.    ec = i;
  1003.    if (ec < bc)
  1004.       error("! no Adobe characters") ;
  1005.  
  1006.    width = charinfo + (ec - bc + 1) ;
  1007.    width[0] = 0 ;
  1008.    nw++ ;
  1009.    for (i=bc; i<=ec; i++)
  1010.       if (0 != (ai=adobeptrs[i])) {
  1011.          width[nw]=ai->width ;
  1012.          for (j=1; width[j]!=ai->width; j++) ;
  1013.          ai->wptr = j ;
  1014.          if (j==nw)
  1015.             nw++ ;
  1016.       }
  1017.    if (nw>256)
  1018.       error("! 256 chars with different widths") ;
  1019.    depth = width + nw ;
  1020.    depth[0] = 0 ;
  1021.    nd = 1 ;
  1022.    for (i=bc; i<=ec; i++)
  1023.       if (0 != (ai=adobeptrs[i])) {
  1024.          depth[nd] = -ai->lly ;
  1025.          for (j=0; depth[j]!=-ai->lly; j++) ;
  1026.          ai->dptr = j ;
  1027.          if (j==nd)
  1028.             nd++ ;
  1029.       }
  1030.    if (nd > 16) {
  1031.       remap(depth, nd, 16) ;
  1032.       nd = 16 ;
  1033.       for (i=bc; i<=ec; i++)
  1034.          if (0 != (ai=adobeptrs[i]))
  1035.             ai->dptr = unsort[ai->dptr] ;
  1036.    }
  1037.    height = depth + nd ;
  1038.    height[0] = 0 ;
  1039.    nh = 1 ;
  1040.    for (i=bc; i<=ec; i++)
  1041.       if (0 != (ai=adobeptrs[i])) {
  1042.          height[nh]=ai->ury ;
  1043.          for (j=0; height[j]!=ai->ury; j++) ;
  1044.          ai->hptr = j ;
  1045.          if (j==nh)
  1046.             nh++ ;
  1047.       }
  1048.    if (nh > 16) {
  1049.       remap(height, nh, 16) ;
  1050.       nh = 16 ;
  1051.       for (i=bc; i<=ec; i++)
  1052.          if (0 != (ai=adobeptrs[i]))
  1053.             ai->hptr = unsort[ai->hptr] ;
  1054.    }
  1055.    italic  = height + nh ;
  1056.    italic[0] = 0 ;
  1057.    ni = 1 ;
  1058.    for (i=bc; i<=ec; i++)
  1059.       if (0 != (ai=adobeptrs[i])) {
  1060.          italic[ni] = ai->urx - ai->width ;
  1061.          if (italic[ni]<0)
  1062.             italic[ni] = 0 ;
  1063.          for (j=0; italic[j]!=italic[ni]; j++) ;
  1064.          ai->iptr = j ;
  1065.          if (j==ni)
  1066.             ni++ ;
  1067.       }
  1068.    if (ni > 64) {
  1069.       remap(italic, ni, 64) ;
  1070.       ni = 64 ;
  1071.       for (i=bc; i<=ec; i++)
  1072.          if (0 != (ai=adobeptrs[i]))
  1073.             ai->iptr = unsort[ai->iptr] ;
  1074.    }
  1075.  
  1076.    for (i=bc; i<=ec; i++)
  1077.       if (0 != (ai=adobeptrs[i]))
  1078.          charinfo[i-bc] = ((long)(ai->wptr)<<24) +
  1079.                            ((long)(ai->hptr)<<20) +
  1080.                             ((long)(ai->dptr)<<16) +
  1081.                              ((long)(ai->iptr)<<10) ;
  1082.  
  1083.    ligkern = italic + ni ;
  1084.    nl = 0 ; /* ligatures and kerns omitted from raw Adobe font */
  1085.    kern = ligkern + nl ;
  1086.    nk = 0 ;
  1087.  
  1088.    newslant = (double)slant - efactor * tan(italicangle*(3.1415926535/180.0)) ;
  1089.    tparam = kern + nk ;
  1090.    tparam[0] = (long)(FIXFACTOR * newslant + 0.5) ;
  1091.    tparam[1] = scale((long)fontspace) ;
  1092.    tparam[2] = (fixedpitch ? 0 : scale((long)(300*efactor+0.5))) ;
  1093.    tparam[3] = (fixedpitch ? 0 : scale((long)(100*efactor+0.5))) ;
  1094.    tparam[4] = scale((long)xheight) ;
  1095.    tparam[5] = scale((long)(1000*efactor+0.5)) ;
  1096.    np = 6 ;
  1097. }
  1098.  
  1099. void
  1100. writesarr(what, len)
  1101. long *what ;
  1102. int len ;
  1103. {
  1104.    register long *p ;
  1105.    int i ;
  1106.  
  1107.    p = what ;
  1108.    i = len ;
  1109.    while (i) {
  1110.       *p = scale(*p) ;
  1111.       (void)scale(*p) ; /* need this kludge for some compilers */
  1112.       p++ ;
  1113.       i-- ;
  1114.    }
  1115.    writearr(what, len) ;
  1116. }
  1117.  
  1118. void
  1119. writetfm() {
  1120.    lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np ;
  1121.    write16(lf) ;
  1122.    write16(lh) ;
  1123.    write16(bc) ;
  1124.    write16(ec) ;
  1125.    write16(nw) ;
  1126.    write16(nh) ;
  1127.    write16(nd) ;
  1128.    write16(ni) ;
  1129.    write16(nl) ;
  1130.    write16(nk) ;
  1131.    write16(ne) ;
  1132.    write16(np) ;
  1133.    writearr(header, lh) ;
  1134.    writearr(charinfo, ec-bc+1) ;
  1135.    writesarr(width, nw) ;
  1136.    writesarr(height, nh) ;
  1137.    writesarr(depth, nd) ;
  1138.    writesarr(italic, ni) ;
  1139.    writearr(ligkern, nl) ;
  1140.    writesarr(kern, nk) ;
  1141.    writearr(tparam, np) ;
  1142. }
  1143.  
  1144. /* OK, the TFM file is done! Now for our next trick, the VPL file. */
  1145.  
  1146. /* For TeX we want to compute a character height that works properly
  1147.  * with accents. The following list of accents doesn't need to be complete. */
  1148. /*
  1149.  *   We only do this if the xheight has a reasonable value.
  1150.  *   (>50)
  1151.  */
  1152. char *accents[] = { "acute", "tilde", "caron", "dieresis", NULL} ;
  1153. int
  1154. texheight(ai)
  1155. register struct adobeinfo *ai ;
  1156. {
  1157.    register char **p;
  1158.    register struct adobeinfo *aci, *acci ;
  1159.    if (xheight <= 50 || *(ai->adobename + 1)) return (ai->ury) ;
  1160.                                            /* that was the simple case */
  1161.    for (p=accents; *p; p++)  /* otherwise we look for accented letters */
  1162.       if (0 != (aci=findadobe(*p))) {
  1163.          strcpy(buffer,ai->adobename) ;
  1164.          strcat(buffer,*p) ;
  1165.          if (0 != (acci=findadobe(buffer)))
  1166.             return (acci->ury - aci->ury + xheight) ;
  1167.       }
  1168.    return (ai->ury) ;
  1169. }
  1170.  
  1171. /* modified tgr to eliminate varargs problems */
  1172.  
  1173. #define vout(s)  fprintf(vplout, s)
  1174. int level ; /* the depth of parenthesis nesting in VPL file being written */
  1175. void vlevout() {
  1176.    register int l = level ;
  1177.    while (l--) vout("   ") ;
  1178. }
  1179. void vlevnlout() {
  1180.    vout("\n") ;
  1181.    vlevout() ;
  1182. }
  1183. #define voutln(str) {fprintf(vplout,"%s\n",str);vlevout();}
  1184. #define voutln2(f,s) {fprintf(vplout,f,s);vlevnlout();}
  1185. #define voutln3(f,a,b) {fprintf(vplout,f,a,b);vlevnlout();}
  1186. #define voutln4(f,a,b,c) {fprintf(vplout,f,a,b,c);vlevnlout();}
  1187. void
  1188. vleft()
  1189. {
  1190.    level++ ;
  1191.    vout("(") ;
  1192. }
  1193.  
  1194. void
  1195. vright()
  1196. {
  1197.    level-- ;
  1198.    voutln(")") ;
  1199. }
  1200.  
  1201. int forceoctal = 0 ;
  1202.  
  1203. char vcharbuf[6] ;
  1204. char *vchar(c)
  1205. int c ;
  1206. {
  1207.    if (forceoctal == 0 &&
  1208. /* changed below to ascii<->ebcdic independence: */
  1209. /* any reason we don't use 'isalnum'? */
  1210.          ( (c>=ASCII_0 && c<=ASCII_9) || (c>=ASCII_A && c<=ASCII_Z) ||
  1211.                       (c>=ASCII_a && c<=ASCII_z) ) )
  1212.       (void) sprintf(vcharbuf,"C %c",
  1213. #ifndef VMCMS
  1214.       c) ;
  1215. #else
  1216.       ascii2ebcdic[c]) ;
  1217. #endif
  1218.    else (void) sprintf(vcharbuf,"O %o", (unsigned)c) ;
  1219.    return (vcharbuf) ;
  1220. }
  1221.  
  1222. void
  1223. writevpl()
  1224. {
  1225.    register int i, j, k ;
  1226.    register struct adobeinfo *ai ;
  1227.    register struct lig *nlig ;
  1228.    register struct kern *nkern ;
  1229.    register struct pcc *npcc ;
  1230.    struct adobeinfo *asucc, *asub, *api ;
  1231.    int xoff, yoff, ht ;
  1232.    char unlabeled ;
  1233.  
  1234.    voutln2("(VTITLE Created by %s)", titlebuf) ;
  1235.    voutln("(COMMENT Please edit that VTITLE if you edit this file)") ;
  1236.    (void)sprintf(obuffer, "TeX-%s%s%s%s", outname,
  1237.       (efactor==1.0? "" : "-E"), (slant==0.0? "" : "-S"),
  1238.                  (makevpl==1? "" : "-CSC")) ;
  1239.    if (strlen(obuffer)>19) { /* too long, will retain first 9 and last 10 */
  1240.       register char *p, *q ;
  1241.       for (p = &obuffer[9], q = &obuffer[strlen(obuffer)-10] ; p<&obuffer[19];
  1242.               p++, q++) *p = *q ;
  1243.       obuffer[19] = '\0' ;
  1244.    }
  1245.    voutln2("(FAMILY %s)" , obuffer) ;
  1246.    {
  1247.       char tbuf[300] ;
  1248.  
  1249.       sprintf(tbuf, "%s + %s", outencoding->name,
  1250. #ifndef VMCMS
  1251.          codingscheme) ;
  1252. #else
  1253.          ebcodingscheme) ;
  1254. #endif
  1255.       if (strlen(tbuf) > 39) {
  1256.          error("Coding scheme too long; shortening to 39 characters.") ;
  1257.          tbuf[39] = 0 ;
  1258.       }
  1259.       voutln2("(CODINGSCHEME %s)", tbuf) ;
  1260.    }
  1261.    voutln("(DESIGNSIZE R 10.0)") ;
  1262.    voutln("(DESIGNUNITS R 1000)") ;
  1263.    voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)") ;
  1264.    voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)") ;
  1265.    voutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff) ;
  1266.    if (boundarychar >= 0)
  1267.       voutln2("(BOUNDARYCHAR O %lo)", (unsigned long)boundarychar) ;
  1268.    vleft() ; voutln("FONTDIMEN") ;
  1269.    if (newslant)
  1270.       voutln2("(SLANT R %f)", newslant) ;
  1271.    voutln2("(SPACE D %d)", fontspace) ;
  1272.    if (! fixedpitch) {
  1273.       voutln2("(STRETCH D %d)", transform(200,0)) ;
  1274.       voutln2("(SHRINK D %d)", transform(100,0)) ;
  1275.    }
  1276.    voutln2("(XHEIGHT D %d)", xheight) ;
  1277.    voutln2("(QUAD D %d)", transform(1000,0)) ;
  1278.    voutln2("(EXTRASPACE D %d)", fixedpitch ? fontspace : transform(111, 0)) ;
  1279.    vright() ;
  1280.    vleft() ; voutln("MAPFONT D 0");
  1281.    voutln2("(FONTNAME %s)", outname) ;
  1282.    voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum) ;
  1283.    vright() ;
  1284.    if (makevpl>1) {
  1285.       vleft() ; voutln("MAPFONT D 1");
  1286.       voutln2("(FONTNAME %s)", outname) ;
  1287.       voutln2("(FONTAT D %d)", (int)(1000.0*capheight+0.5)) ;
  1288.       voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum) ;
  1289.       vright() ;
  1290.    }
  1291.  
  1292.    for (i=0; i<256 && texptrs[i]==NULL; i++) ;
  1293.    bc = i ;
  1294.    for (i=255; i>=0 && texptrs[i]==NULL; i--) ;
  1295.    ec = i;
  1296.  
  1297.    vleft() ; voutln("LIGTABLE") ;
  1298.    ai = findadobe("||") ;
  1299.    unlabeled = 1 ;
  1300.    for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1301.       if (0 != (asucc=findadobe(nlig->succ))) {
  1302.          if (0 != (asub=findadobe(nlig->sub)))
  1303.             if (asucc->texnum>=0)
  1304.                if (asub->texnum>=0) {
  1305.                   if (unlabeled) {
  1306.                      voutln("(LABEL BOUNDARYCHAR)") ;
  1307.                      unlabeled = 0 ;
  1308.                   }
  1309.                   for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1310.                      voutln4("(%s %s O %o)", vplligops[nlig->op],
  1311.                          vchar(j), (unsigned)asub->texnum) ;
  1312.                   }
  1313.                }
  1314.        }
  1315.    if (! unlabeled) voutln("(STOP)") ;
  1316.    for (i=bc; i<=ec; i++)
  1317.       if ((ai=texptrs[i]) && ai->texnum == i) {
  1318.          unlabeled = 1 ;
  1319.          if (uppercase[i]==NULL) /* omit ligatures from smallcap lowercase */
  1320.             for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1321.                if (0 != (asucc=findadobe(nlig->succ)))
  1322.                   if (0 != (asub=findadobe(nlig->sub)))
  1323.                      if (asucc->texnum>=0)
  1324.                         if (asub->texnum>=0) {
  1325.                            if (unlabeled) {
  1326.                               for (j = ai->texnum; j >= 0; j = nexttex[j])
  1327.                                  voutln2("(LABEL %s)", vchar(j)) ;
  1328.                               unlabeled = 0 ;
  1329.                            }
  1330.                            for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1331.                               voutln4("(%s %s O %o)", vplligops[nlig->op],
  1332.                                    vchar(j), (unsigned)asub->texnum) ;
  1333.                               if (nlig->boundleft)
  1334.                                  break ;
  1335.                            }
  1336.                         }
  1337.          for (nkern = (uppercase[i] ? uppercase[i]->kerns : ai->kerns);
  1338.                     nkern; nkern=nkern->next)
  1339.             if (0 != (asucc=findadobe(nkern->succ)))
  1340.                for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1341.                   if (uppercase[j]==NULL) {
  1342.                      if (unlabeled) {
  1343.                         for (k = ai->texnum; k >= 0; k = nexttex[k])
  1344.                            voutln2("(LABEL %s)", vchar(k)) ;
  1345.                         unlabeled = 0 ;
  1346.                      }
  1347.                      if (uppercase[i]) {
  1348.                         if (lowercase[j]) {
  1349.                            for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
  1350.                               voutln3("(KRN %s R %.1f)", vchar(k),
  1351.                                     capheight*nkern->delta) ;
  1352.                         } else voutln3("(KRN %s R %.1f)",
  1353.                                  vchar(j), capheight*nkern->delta) ;
  1354.                      } else {
  1355.                         voutln3("(KRN %s R %d)", vchar(j),
  1356.                                 nkern->delta) ;
  1357.                         if (lowercase[j])
  1358.                            for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
  1359.                               voutln3("(KRN %s R %.1f)", vchar(k),
  1360.                                 capheight*nkern->delta) ;
  1361.                      }
  1362.                   }
  1363.                }
  1364.          if (! unlabeled) voutln("(STOP)") ;
  1365.       }
  1366.    vright() ;
  1367.  
  1368.    for (i=bc; i<=ec; i++)
  1369.       if (0 != (ai=texptrs[i])) {
  1370.          vleft() ; fprintf(vplout, "CHARACTER %s", vchar(i)) ;
  1371.          if (*vcharbuf=='C') {
  1372.             voutln("") ;
  1373.          } else
  1374.             voutln2(" (comment %s)", ai->adobename) ;
  1375.          if (uppercase[i]) {
  1376.             ai=uppercase[i] ;
  1377.             voutln2("(CHARWD R %.1f)", capheight * (ai->width)) ;
  1378.             if (0 != (ht=texheight(ai)))
  1379.                voutln2("(CHARHT R %.1f)", capheight * ht) ;
  1380.             if (ai->lly)
  1381.                voutln2("(CHARDP R %.1f)", -capheight * ai->lly) ;
  1382.             if (ai->urx > ai->width)
  1383.                voutln2("(CHARIC R %.1f)", capheight * (ai->urx - ai->width)) ;
  1384.          } else {
  1385.             voutln2("(CHARWD R %d)", ai->width) ;
  1386.             if (0 != (ht=texheight(ai)))
  1387.                voutln2("(CHARHT R %d)", ht) ;
  1388.             if (ai->lly)
  1389.                voutln2("(CHARDP R %d)", -ai->lly) ;
  1390.             if (ai->urx > ai->width)
  1391.                voutln2("(CHARIC R %d)", ai->urx - ai->width) ;
  1392.          }
  1393.          if (ai->adobenum != i || uppercase[i]) {
  1394.             vleft() ; voutln("MAP") ;
  1395.             if (uppercase[i]) voutln("(SELECTFONT D 1)") ;
  1396.             if (ai->pccs && ai->adobenum < 0) {
  1397.                xoff = 0 ; yoff = 0 ;
  1398.                for (npcc = ai->pccs; npcc; npcc=npcc->next)
  1399.                   if (0 != (api=findadobe(npcc->partname)))
  1400.                      if (api->texnum>=0) {
  1401.                         if (npcc->xoffset != xoff) {
  1402.                            if (uppercase[i]) {
  1403.                               voutln2("(MOVERIGHT R %.1f)",
  1404.                                       capheight * (npcc->xoffset - xoff)) ;
  1405.                            } else voutln2("(MOVERIGHT R %d)",
  1406.                                       npcc->xoffset - xoff) ;
  1407.                            xoff = npcc->xoffset ;
  1408.                         }
  1409.                         if (npcc->yoffset != yoff) {
  1410.                            if (uppercase[i]) {
  1411.                               voutln2("(MOVEUP R %.1f)",
  1412.                                       capheight * (npcc->yoffset - yoff)) ;
  1413.                            } else voutln2("(MOVEUP R %d)",
  1414.                                       npcc->yoffset - yoff) ;
  1415.                            yoff = npcc->yoffset ;
  1416.                         }
  1417.                         voutln2("(SETCHAR O %o)", (unsigned)api->adobenum) ;
  1418.                         xoff += texptrs[api->texnum]->width ;
  1419.                      }
  1420.             } else voutln2("(SETCHAR O %o)", (unsigned)ai->adobenum) ;
  1421.             vright() ;
  1422.          }
  1423.          vright() ;
  1424.       }
  1425.    if (level) error("! I forgot to match the parentheses") ;
  1426. }
  1427.  
  1428. void usage(f)
  1429. FILE *f ;
  1430. {
  1431.    (void)fprintf(f,
  1432.  "afm2tfm 7.8, Copyright 1990-93 by Radical Eye Software\n") ;
  1433.    (void)fprintf(f,
  1434.  "Usage: afm2tfm foo[.afm] [-O] [-u] [-v|-V bar[.vpl]]\n") ;
  1435.    (void)fprintf(f,
  1436.  "                 [-e expansion] [-s slant] [-c capheight]\n") ;
  1437.    (void)fprintf(f,
  1438.  "                 [-p|-t|-T encodingfile] [foo[.tfm]]\n") ;
  1439. }
  1440.  
  1441. void
  1442. openfiles(argc, argv)
  1443. int argc ;
  1444. char *argv[] ;
  1445. {
  1446.    register int lastext ;
  1447.    register int i ;
  1448.    int arginc ;
  1449.    extern void exit() ;
  1450.  
  1451.    tfmout = (FILE *)NULL ;
  1452.    if (argc == 1) {
  1453.       usage(stdout) ;
  1454.       exit(0) ;
  1455.    }
  1456.  
  1457. #if defined MSDOS || defined OS2
  1458.    /* Make VPL file identical to that created under Unix */
  1459.    (void)sprintf(titlebuf, "afm2tfm %s", argv[1]) ;
  1460. #else
  1461. #ifdef VMCMS
  1462.    /* Make VPL file identical to that created under Unix */
  1463.    (void)sprintf(titlebuf, "afm2tfm %s", argv[1]) ;
  1464. #else
  1465.    (void)sprintf(titlebuf, "%s %s", argv[0], argv[1]) ;
  1466. #endif
  1467. #endif
  1468.    (void)strcpy(inname, argv[1]) ;
  1469.    lastext = -1 ;
  1470.    for (i=0; inname[i]; i++)
  1471.       if (inname[i] == '.')
  1472.          lastext = i ;
  1473.       else if (inname[i] == '/' || inname[i] == ':')
  1474.          lastext = -1 ;
  1475.    if (lastext == -1) (void)strcat(inname, ".afm") ;
  1476.  
  1477.    while (argc>2 && *argv[2]=='-') {
  1478.       arginc = 2 ;
  1479.       i = argv[2][1] ;
  1480.       if (i == '/')
  1481.          i = argv[2][2] - 32 ; /* /a ==> A for VMS */
  1482.       switch (i) {
  1483. case 'V': makevpl++ ;
  1484. case 'v': makevpl++ ;
  1485.          (void)strcpy(outname, argv[3]) ;
  1486.          lastext = -1 ;
  1487.          for (i=0; outname[i]; i++)
  1488.             if (outname[i] == '.')
  1489.                lastext = i ;
  1490.             else if (outname[i] == '/' || outname[i] == ':')
  1491.                lastext = -1 ;
  1492.          if (lastext == -1) (void)strcat(outname, ".vpl") ;
  1493. #ifndef VMCMS
  1494.          if ((vplout=fopen(outname, WRITEBIN))==NULL)
  1495. #else
  1496.          if ((vplout=fopen(outname, "w"))==NULL)
  1497. #endif
  1498.             error("! can't open vpl output file") ;
  1499.          break ;
  1500. case 'e': if (sscanf(argv[3], "%f", &efactor)==0 || efactor<0.01)
  1501.             error("! Bad extension factor") ;
  1502.          efactorparam = argv[3] ;
  1503.          break ;
  1504. case 'c':
  1505.          if (sscanf(argv[3], "%f", &capheight)==0 || capheight<0.01)
  1506.             error("! Bad small caps height") ;
  1507.          break ;
  1508. case 's': if (sscanf(argv[3], "%f", &slant)==0)
  1509.             error("! Bad slant parameter") ;
  1510.          slantparam = argv[3] ;
  1511.          break ;
  1512. case 'P':
  1513. case 'p':
  1514.          inenname = argv[3] ;
  1515.          break ;
  1516. case 'T':
  1517.          inenname = outenname = argv[3] ;
  1518.          break ;
  1519. case 't':
  1520.          outenname = argv[3] ;
  1521.          break ;
  1522. case 'O':
  1523.          forceoctal = 1 ;
  1524.          arginc = 1 ;
  1525.          break ;
  1526. case 'u':
  1527.          pedantic = 1 ;
  1528.          arginc = 1 ;
  1529.          break ;
  1530. default: (void)fprintf(stderr, "Unknown option %s %s will be ignored.\n",
  1531.                          argv[2], argv[3]) ;
  1532.       }
  1533.       for (i=0; i<arginc; i++) {
  1534.          (void)sprintf(titlebuf + strlen(titlebuf), " %s", argv[2]) ;
  1535.          argv++ ;
  1536.          argc-- ;
  1537.       }
  1538.    }
  1539.  
  1540.    if ((afmin=fopen(inname, "r"))==NULL)
  1541.       error("! can't open afm input file") ;
  1542.  
  1543.    if (argc>3 || (argc==3 && *argv[2]=='-')) {
  1544.       usage(stderr) ;
  1545.       error("! incorrect usage") ;
  1546.    }
  1547.  
  1548.    if (argc == 2) (void)strcpy(outname, inname) ;
  1549.    else (void)strcpy(outname, argv[2]) ;
  1550.  
  1551.    lastext = -1 ;
  1552.    for (i=0; outname[i]; i++)
  1553.       if (outname[i] == '.')
  1554.          lastext = i ;
  1555.       else if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1556.          lastext = -1 ;
  1557.    if (argc == 2) {
  1558.       outname[lastext] = 0 ;
  1559.       lastext = -1 ;
  1560.    }
  1561.    if (lastext == -1) {
  1562.       lastext = strlen(outname) ;
  1563.       (void)strcat(outname, ".tfm") ;
  1564.    }
  1565.    if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
  1566.       error("! can't open tfm output file") ;
  1567.    outname[lastext] = 0 ;
  1568. /*
  1569.  *   Now we strip off any directory information, so we only use the
  1570.  *   base name in the vf file.  We accept any of /, :, or \ as directory
  1571.  *   delimiters, so none of these are available for use inside the
  1572.  *   base name; this shouldn't be a problem.
  1573.  */
  1574.    for (i=0, lastext=0; outname[i]; i++)
  1575.       if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1576.          lastext = i + 1 ;
  1577.    if (lastext)
  1578.       strcpy(outname, outname + lastext) ;
  1579. }
  1580. /*
  1581.  *   Some routines to remove kerns that match certain patterns.
  1582.  */
  1583. struct kern *rmkernmatch(k, s)
  1584. struct kern *k ;
  1585. char *s ;
  1586. {
  1587.    struct kern *nk ;
  1588.  
  1589.    while (k && strcmp(k->succ, s)==0)
  1590.       k = k->next ;
  1591.    if (k) {
  1592.       for (nk = k; nk; nk = nk->next)
  1593.          while (nk->next && strcmp(nk->next->succ, s)==0)
  1594.             nk->next = nk->next->next ;
  1595.    }
  1596.    return k ;
  1597. }
  1598. /*
  1599.  *   Recursive to one level.
  1600.  */
  1601. void rmkern(s1, s2, ai)
  1602. char *s1, *s2 ;
  1603. struct adobeinfo *ai ;
  1604. {
  1605.    if (ai == 0) {
  1606.       if (strcmp(s1, "*") == 0) {
  1607.          for (ai=adobechars; ai; ai = ai->next)
  1608.             rmkern(s1, s2, ai) ;
  1609.          return ;
  1610.       } else {
  1611.          ai = findadobe(s1) ;
  1612.          if (ai == 0)
  1613.             return ;
  1614.       }
  1615.    }
  1616.    if (strcmp(s2, "*")==0)
  1617.       ai->kerns = 0 ; /* drop them on the floor */
  1618.    else
  1619.       ai->kerns = rmkernmatch(ai->kerns, s2) ;
  1620. }
  1621. int sawligkern ;
  1622. /*
  1623.  *   Reads a ligkern line, if this is one.  Assumes the first character
  1624.  *   passed is `%'.
  1625.  */
  1626. void checkligkern(s)
  1627. char *s ;
  1628. {
  1629.    char *oparam = param ;
  1630.    char *mlist[5] ;
  1631.    int n ;
  1632.  
  1633.    s++ ;
  1634.    while (*s && *s <= ' ')
  1635.       s++ ;
  1636.    if (strncmp(s, "LIGKERN", 7)==0) {
  1637.       sawligkern = 1 ;
  1638.       s += 7 ;
  1639.       while (*s && *s <= ' ')
  1640.          s++ ;
  1641.       param = s ;
  1642.       while (*param) {
  1643.          for (n=0; n<5;) {
  1644.             if (*param == 0)
  1645.                break ;
  1646.             mlist[n] = paramstring() ;
  1647.             if (strcmp(mlist[n], ";") == 0)
  1648.                break ;
  1649.             n++ ;
  1650.          }
  1651.          if (n > 4)
  1652.             error("! too many parameters in lig kern data") ;
  1653.          if (n < 3)
  1654.             error("! too few parameters in lig kern data") ;
  1655.          if (n == 3 && strcmp(mlist[1], "{}") == 0) { /* rmkern command */
  1656.             rmkern(mlist[0], mlist[2], (struct adobeinfo *)0) ;
  1657.          } else if (n == 3 && strcmp(mlist[0], "||") == 0 &&
  1658.                               strcmp(mlist[1], "=") == 0) { /* bc command */
  1659.             struct adobeinfo *ai = findadobe("||") ;
  1660.  
  1661.             if (boundarychar != -1)
  1662.                error("! multiple boundary character commands?") ;
  1663.             if (sscanf(mlist[2], "%d", &n) != 1)
  1664.                error("! expected number assignment for boundary char") ;
  1665.             if (n < 0 || n > 255)
  1666.                error("! boundary character number must be 0..255") ;
  1667.             boundarychar = n ;
  1668.             if (ai == 0)
  1669.                error("! internal error: boundary char") ;
  1670.             ai->texnum = n ; /* prime the pump, so to speak, for lig/kerns */
  1671.          } else if (n == 4) {
  1672.             int op = -1 ;
  1673.             struct adobeinfo *ai ;
  1674.  
  1675.             for (n=0; encligops[n]; n++)
  1676.                if (strcmp(mlist[2], encligops[n])==0) {
  1677.                   op = n ;
  1678.                   break ;
  1679.                }
  1680.             if (op < 0)
  1681.                error("! bad ligature op specified") ;
  1682.             if (0 != (ai = findadobe(mlist[0]))) {
  1683.                struct lig *lig ;
  1684.  
  1685.                if (findadobe(mlist[2]))     /* remove coincident kerns */
  1686.                   rmkern(mlist[0], mlist[1], ai) ;
  1687.                if (strcmp(mlist[3], "||") == 0)
  1688.                   error("! you can't lig to the boundary character!") ;
  1689.                if (! fixedpitch) { /* fixed pitch fonts get *0* ligs */
  1690.                   for (lig=ai->ligs; lig; lig = lig->next)
  1691.                      if (strcmp(lig->succ, mlist[1]) == 0)
  1692.                         break ; /* we'll re-use this structure */
  1693.                   if (lig == 0) {
  1694.                      lig = newlig() ;
  1695.                      lig->succ = newstring(mlist[1]) ;
  1696.                      lig->next = ai->ligs ;
  1697.                      ai->ligs = lig ;
  1698.                   }
  1699.                   lig->sub = newstring(mlist[3]) ;
  1700.                   lig->op = op ;
  1701.                   if (strcmp(mlist[1], "||")==0) {
  1702.                      lig->boundleft = 1 ;
  1703.                      if (strcmp(mlist[0], "||")==0)
  1704.                         error("! you can't lig boundarychar boundarychar!") ;
  1705.                   } else
  1706.                      lig->boundleft = 0 ;
  1707.                }
  1708.             }
  1709.          } else
  1710.             error("! bad form in LIGKERN command") ;
  1711.       }
  1712.    }
  1713.    param = oparam ;
  1714. }
  1715. /*
  1716.  *   Here we get a token from the AFM file.  We parse just as much PostScript
  1717.  *   as we expect to find in an encoding file.  We allow commented lines and
  1718.  *   names like 0, .notdef, _foo_.  We do not allow //abc.
  1719.  */
  1720. char smbuffer[100] ;    /* for tokens */
  1721. char *gettoken() {
  1722.    char *p, *q ;
  1723.  
  1724.    while (1) {
  1725.       while (param == 0 || *param == 0) {
  1726.          if (getline() == 0)
  1727.             error("! premature end in encoding file") ;
  1728.          for (p=buffer; *p; p++)
  1729.             if (*p == '%') {
  1730.                if (ignoreligkern == 0)
  1731.                   checkligkern(p) ;
  1732.                *p = 0 ;
  1733.                break ;
  1734.             }
  1735.       }
  1736.       while (*param && *param <= ' ')
  1737.          param++ ;
  1738.       if (*param) {
  1739.          if (*param == '[' || *param == ']' ||
  1740.              *param == '{' || *param == '}') {
  1741.             smbuffer[0] = *param++ ;
  1742.             smbuffer[1] = 0 ;
  1743.             return smbuffer ;
  1744.          } else if (*param == '/' || *param == '-' || *param == '_' ||
  1745.                     *param == '.' ||
  1746.                     ('0' <= *param && *param <= '9') ||
  1747.                     ('a' <= *param && *param <= 'z') ||
  1748.                     ('A' <= *param && *param <= 'Z')) {
  1749.             smbuffer[0] = *param ;
  1750.             for (p=param+1, q=smbuffer+1;
  1751.                         *p == '-' || *p == '_' || *p == '.' ||
  1752.                         ('0' <= *p && *p <= '9') ||
  1753.                         ('a' <= *p && *p <= 'z') ||
  1754.                         ('A' <= *p && *p <= 'Z'); p++, q++)
  1755.                *q = *p ;
  1756.             *q = 0 ;
  1757.             param = p ;
  1758.             return smbuffer ;
  1759.          }
  1760.       }
  1761.    }
  1762. }
  1763. void getligkerndefaults() {
  1764.    int i ;
  1765.  
  1766.    for (i=0; staticligkern[i]; i++) {
  1767.       strcpy(buffer, staticligkern[i]) ;
  1768.       strcpy(obuffer, staticligkern[i]) ;
  1769.       param = buffer ;
  1770.       checkligkern(buffer) ;
  1771.    }
  1772. }
  1773. /*
  1774.  *   This routine reads in an encoding file, given the name.  It returns
  1775.  *   the final total structure.  It performs a number of consistency checks.
  1776.  */
  1777. struct encoding *readencoding(enc)
  1778. char *enc ;
  1779. {
  1780.    char *p ;
  1781.    int i ;
  1782.    struct encoding *e =
  1783.       (struct encoding *)mymalloc((unsigned long)sizeof(struct encoding)) ;
  1784.  
  1785.    sawligkern = 0 ;
  1786.    if (afmin)
  1787.       error("! oops; internal afmin error") ;
  1788.    if (enc) {
  1789.       afmin = fopen(enc, "r") ;
  1790.       param = 0 ;
  1791.       if (afmin == 0)
  1792.          error("! couldn't open that encoding file") ;
  1793.       p = gettoken() ;
  1794.       if (*p != '/' || p[1] == 0)
  1795.          error("! first token in encoding must be literal encoding name") ;
  1796.       e->name = newstring(p+1) ;
  1797.       p = gettoken() ;
  1798.       if (strcmp(p, "["))
  1799.          error("! second token in encoding must be mark ([) token") ;
  1800.       for (i=0; i<256; i++) {
  1801.          p = gettoken() ;
  1802.          if (*p != '/' || p[1] == 0)
  1803.             error("! tokens 3 to 257 in encoding must be literal names") ;
  1804.          e->vec[i] = newstring(p+1) ;
  1805.       }
  1806.       p = gettoken() ;
  1807.       if (strcmp(p, "]"))
  1808.          error("! token 258 in encoding must be make-array (])") ;
  1809.       while (getline()) {
  1810.          for (p=buffer; *p; p++)
  1811.             if (*p == '%') {
  1812.                if (ignoreligkern == 0)
  1813.                   checkligkern(p) ;
  1814.                *p = 0 ;
  1815.                break ;
  1816.             }
  1817.       }
  1818.       fclose(afmin) ;
  1819.       afmin = 0 ;
  1820.       if (ignoreligkern == 0 && sawligkern == 0)
  1821.          getligkerndefaults() ;
  1822.    } else {
  1823.       e = &staticencoding ;
  1824.       getligkerndefaults() ;
  1825.    }
  1826.    param = 0 ;
  1827.    return e ;
  1828. }
  1829. /*
  1830.  *   This routine prints out the line that needs to be added to psfonts.map.
  1831.  */
  1832. void conspsfonts() {
  1833.    (void)printf("%s %s", outname,
  1834. #ifndef VMCMS
  1835.    fontname) ;
  1836. #else /* VM/CMS: fontname is ascii, so we use ebfontname */
  1837.    ebfontname) ;
  1838. #endif
  1839.    if (slantparam || efactorparam || inenname) {
  1840.       (void)printf(" \"") ;
  1841.       if (slantparam)
  1842.          (void)printf(" %s SlantFont", slantparam) ;
  1843.       if (efactorparam)
  1844.          (void)printf(" %s ExtendFont", efactorparam) ;
  1845.       if (inenname)
  1846.          (void)printf(" %s ReEncodeFont", inencoding->name) ;
  1847.       (void)printf(" \"") ;
  1848.       if (inenname)
  1849.          (void)printf(" <%s", inenname) ;
  1850.    }
  1851.    (void)printf("\n") ;
  1852. }
  1853. #ifndef VMS
  1854. void
  1855. #endif
  1856. main(argc, argv)
  1857. int argc ;
  1858. char *argv[] ;
  1859. {
  1860.    int i ;
  1861.    extern void exit() ;
  1862.  
  1863.    for (i=0; i<256; i++)
  1864.       nexttex[i] = -1 ; /* encoding chains have length 0 */
  1865.    tfmdata = (long *)mymalloc((unsigned long)40000L) ;
  1866.    openfiles(argc, argv) ;
  1867.    readadobe() ;
  1868.    if (fontspace == 0) {
  1869.       struct adobeinfo *ai ;
  1870.  
  1871.       if (0 != (ai = findadobe("space")))
  1872.          fontspace = ai->width ;
  1873.       else if (adobeptrs[32])
  1874.          fontspace = adobeptrs[32]->width ;
  1875.       else
  1876.          fontspace = transform(500, 0) ;
  1877.    }
  1878.    handlereencoding() ;
  1879.    buildtfm() ;
  1880.    writetfm() ;
  1881.    conspsfonts() ;
  1882.    if (makevpl) {
  1883.       assignchars() ;
  1884.       if (makevpl>1) upmap() ;
  1885.       writevpl() ;
  1886.    }
  1887.    exit(0) ;
  1888.    /*NOTREACHED*/
  1889. }
  1890.